package com.aruba.filter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.LightingColorFilter;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * 色彩矩阵ColorMatrix
 */
public class LightingColorFilterView extends View {
    private Bitmap bitmap;
    
    public LightingColorFilterView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);

        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.xyjy2);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        //画原图
        Paint paint = new Paint();
        RectF rectF = new RectF(100, 100, 100 + bitmap.getWidth() / 2, 100 + bitmap.getHeight() / 2);
        canvas.drawBitmap(bitmap, null, rectF, paint);

        //画设置ColorFilter效果后的图
        rectF = new RectF(600, 100, 600 + bitmap.getWidth() / 2, 100 + bitmap.getHeight() / 2);
        // LightingColorFilter只是修改RGB值
        //每个ff都分别代表R，G，B，下面是将RGB加上纯红色，因为后面add为0xff0000
        LightingColorFilter lightingColorFilter = new LightingColorFilter(0xffffff,0xff0000);
        paint.setColorFilter(lightingColorFilter);
        canvas.drawBitmap(bitmap, null, rectF, paint);
    }

}
